<template>
  <div class="mains">
    <div class="liveList">
      <div class="fixedTop">
        <go-back :white="true"></go-back>
        <div style="height: 10px; background: #fff;"></div>
        <div class="tabNave">
          <div class="tabBox flex-h">
            <span :class="['flex1', tabView === 'select1' ? 'active' : '']" @click="tabCike('select1')">录取评测</span>
            <span :class="['flex1', tabView === 'select2' ? 'active' : '']" @click="tabCike('select2')">压力测试</span>
            <span :class="['flex1', tabView === 'select3' ? 'active' : '']" @click="tabCike('select3')">心理健康测评</span>
            <span :class="['flex1', tabView === 'select4' ? 'active' : '']" @click="tabCike('select4')">学习测评</span>
          </div>
        </div>
      </div>
      <!-- <div style="height: 1.8rem;"></div> -->
      <scrollerEdit lock-x ref="scrollerBottom">
        <div class="tabCon" style="padding-bottom:2rem" ref="scrollHeight">
          <div style="height:1.8rem"></div>
          <keep-alive>
            <component v-bind:is="tabView" @myblurs="getToTop" @resetScroller="resets"></component>
          </keep-alive>
        </div>
      </scrollerEdit>
    </div>
  </div>
</template>
<script>
import goBack from '~/components/goBack'
import scrollerEdit from '~/components/scrollerEdit'
export default {
  components: {
    goBack,
    scrollerEdit,
    select1(resolve) {
      require(['./components/examination'], resolve)
    },
    select2(resolve) {
      require(['./components/pressureTest'], resolve)
    },
    select3(resolve) {
      require(['./components/mentalityTest'], resolve)
    },
    select4(resolve) {
      require(['./components/studyTest'], resolve)
    },
  },
  data() {
    return {
      tabIndex: 1,
      tabView: 'select1',
      //   scrollerHeight: '',
    }
  },
  watch: {
    // scrollerHeight(e) {
    // //   console.log('e: ', e)
    // },
  },
  beforeRouteLeave(to, from, next) {
    sessionStorage.setItem('sxTestTab', this.tabView)
    next()
  },
  mounted: function() {
    // this.scrollerHeight = this.$refs.scrollHeight.offsetHeight
    // console.log('this.$refs.scrollHeight.offsetHeight: ', this.$refs.scrollHeight.offsetHeight)
    if (sessionStorage.getItem('sxTestTab')) {
      this.tabView = sessionStorage.getItem('sxTestTab')
    }
    this.$visit('sxAssess/home')
  },
  methods: {
    resets() {
      this.$nextTick(() => {
        this.$refs.scrollerBottom.reset()
      })
    },
    tabCike(select) {
      this.tabView = select
      this.$nextTick(() => {
        this.$refs.scrollerBottom.reset({
          top: 0,
        })
      })
    },
    getToTop() {
      let _this = this
      const u = navigator.userAgent
      const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
      if (isiOS) {
        window.scroll(0, 0)
      } else {
        setTimeout(function() {
          this.$refs.scrollerBottom.reset({
            top: 0,
          })
          // window.scroll(0, 0)
        }, 10)
      }
    },
  },
}
</script>
<style scoped lang="less">
.fixedTop {
  width: 100%;
  height: 1rem;
  left: 0;
  top: 0;
  position: fixed;
  z-index: 10;
}
.tabNave {
  width: 100%;
  height: 44px;
  background: #fff;
  span {
    text-align: center;
    height: 0.5rem;
    line-height: 0.5rem;
    overflow: inherit;
    font-size: 0.28rem;
    font-weight: 400;
    color: rgba(34, 34, 34, 1);
  }
  .active {
    position: relative;
    font-weight: 600;
    color: rgba(34, 34, 34, 1);
  }
  .active::after {
    content: '';
    position: absolute;
    width: 0.4rem;
    height: 0.08rem;
    background: rgba(255, 173, 13, 1);
    border-radius: 0.04rem;
    left: 50%;
    margin-left: -0.2rem;
    bottom: -0.2rem;
  }
}
</style>
